import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:wheel_of_fortune/http/wheel_server.dart';
import 'package:wheel_of_fortune/utils/utils.dart';

import 'customer_button.dart';

class Topup extends StatefulWidget {
  ///
  final double topUpAmount;
  final rotaryTableId;
  const Topup(
      {this.topUpAmount = 10.0,
      this.rotaryTableId = '',
      Key key})
      : super(key: key);

  @override
  _TopupState createState() => _TopupState();
}

class _TopupState extends State<Topup> {
  bool loading = false;
  exchange() async {
    try {
      setState(() {
        loading = true;
      });
      await WheelService().topUpPresented(widget.topUpAmount,);
      await Fluttertoast.showToast(msg: 'Top-up success！', gravity: ToastGravity.CENTER);
      Navigator.of(context).pop(true);
    } catch (e) {
      Navigator.of(context).pop(false);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Container(
            color: mainColor,
            child: Image.asset(
              'assets/images/messages_alerts.png',
              fit: BoxFit.fill,
            ),
          ),
          Container(
            padding: EdgeInsets.only(top: 30, bottom: 10),
            alignment: Alignment.center,
            child: Text(
              'Insufficient Spins!',
              textAlign: TextAlign.center,
              style: TextStyle(
                color: mainColor,
                fontSize: 26,
                fontFamily: 'Avenir Next LT Pro',
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
          Container(
            padding: EdgeInsets.only(top: 0, bottom: 50,left: 15,right: 15),
            alignment: Alignment.center,
            child: Text(
              'Top-up more than Php ${widget.topUpAmount} to earn 1 more spin.',
              textAlign: TextAlign.center,
              strutStyle:
                  StrutStyle(forceStrutHeight: true, height: 1, leading: 0.9),
              style: TextStyle(
                color: mainColor,
                fontSize: 14,
                fontFamily: 'Avenir Next LT Pro',
                fontWeight: FontWeight.w400,
              ),
            ),
          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              BgButton(
                title: 'Top-up Account',
                width: 200.0,
                color: loading ? yellowColor : deepYellowColor,
                onTap: loading ? () {} : exchange,
              ),
              SizedBox(
                height: 20,
              ),
              InkWell(
                onTap: loading ? null : () => Navigator.of(context).pop(false),
                child: Text(
                  'Cancel',
                  style: TextStyle(
                    color: greyDBColor,
                    fontSize: 16,
                    fontFamily: 'Avenir Next LT Pro',
                  ),
                ),
              ),
            ],
          ),
          SizedBox(
            height: 30,
          ),
        ],
      ),
    );
  }
}
